Nested loop control

ABSTRACT

A nested loop controller includes a first register having a first value initialized to an initial first value, a second register having a second value initialized to an initial second value, and a third register configured as a predicate FIFO, initialized to have a third value. The second value is advanced in response to a tick instruction during execution of a loop. In response to the second value reaching a second threshold, the second register is reset to the initial second value. The nested loop controller further includes a comparator coupled to the second register and to the predicate FIFO and configured to provide an outer loop indicator value as input to the predicate FIFO when the second value is equal to the second threshold, and provide an inner loop indicator value as input to the predicate FIFO when the second value is not equal to the second threshold.

BACKGROUND

Modern digital signal processors (DSP) face multiple challenges. DSPsoften execute software that includes nested loops, which include aninner loop and one or more outer loops. In order to improve performanceof a DSP, certain instructions may be executed in a pipelined fashion,in which multiple instructions are executed at the same time bydifferent functional units of the DSP. However, executing nested loopsin a pipelined fashion introduces difficulties in determining whether toexecute an instruction associated with the one or more outer loops, forexample determining a predicate for the instruction in an efficientmanner.

SUMMARY

In accordance with at least one example of the disclosure, a nested loopcontroller includes a first register having a first value initialized toan initial first value, a second register having a second valueinitialized to an initial second value, and a third register configuredas a predicate FIFO, initialized to have a third value. The third valuecomprises a first bit equal to an outer loop indicator. The second valueis advanced in response to a tick instruction during execution of aloop. In response to the second value reaching a second threshold, thesecond register is reset to the initial second value. The nested loopcontroller further includes a comparator coupled to the second registerand to the predicate FIFO and configured to provide an outer loopindicator value as input to the predicate FIFO when the second value isequal to the second threshold, and provide an inner loop indicator valueas input to the predicate FIFO when the second value is not equal to thesecond threshold.

In accordance with another example of the disclosure, a method includesinitializing a first register, having an associated first value, to aninitial first value; initializing a second register, having anassociated second value, to an initial second value; initializing athird register, having an associated third value, to an initial thirdvalue, wherein the third register is configured as a predicate first-in,first-out buffer (FIFO); advancing the second value in response to atick instruction during executing of a loop; resetting the secondregister to the initial second value in response to the second valuereaching a second threshold; providing an outer loop indicator value asinput to the predicate FIFO when the second value is equal to the secondthreshold; and providing an inner loop indicator value as input to thepredicate FIFO when the second value is not equal to the secondthreshold.

BRIEF DESCRIPTION OF THE DRAWINGS

For a detailed description of various examples, reference will now bemade to the accompanying drawings in which:

FIG. 1 shows a dual scalar/vector datapath processor in accordance withvarious examples;

FIG. 2 shows the registers and functional units in the dualscalar/vector datapath processor illustrated in FIG. 1 and in accordancewith various examples;

FIG. 3 shows an exemplary global scalar register file;

FIG. 4 shows an exemplary local scalar register file shared byarithmetic functional units;

FIG. 5 shows an exemplary local scalar register file shared by multiplyfunctional units;

FIG. 6 shows an exemplary local scalar register file shared byload/store units;

FIG. 7 shows an exemplary global vector register file;

FIG. 8 shows an exemplary predicate register file;

FIG. 9 shows an exemplary local vector register file shared byarithmetic functional units;

FIG. 10 shows an exemplary local vector register file shared by multiplyand correlation functional units;

FIG. 11 shows pipeline phases of the central processing unit inaccordance with various examples;

FIG. 12 shows sixteen instructions of a single fetch packet inaccordance with various examples;

FIGS. 13A and 13B show schematic diagrams of nested loop controllers inaccordance with various examples;

FIGS. 14A-1, 14A-2, 14B, and 14C show exemplary pseudo-assembly codeinstructions that result from compiling a coalesced nested loop inaccordance with various examples; and

FIG. 15 shows a block diagram of an exemplary system for compiling anested loop in accordance with various examples.

DETAILED DESCRIPTION

In many typical DSP applications, loops comprise a majority of thenumber of cycles, or MIPS, and thus performance of loops can affect theperformance of the entire application. As explained above, DSPs oftenexecute software that includes nested loops, which include an inner loopand one or more outer loops. Some common examples are finite impulseresponse (FIR) and infinite impulse response (IIR) filters, fast Fouriertransforms (FFTs), and vision code. A perfectly nested loop is a nestedloop in which all of the instructions to be executed are contained onlyin the inner loop, and the outer loops contain no instructions beyondthe loop itself to be executed. An imperfectly nested loop is a nestedloop in which one or more of the outer loops contain instructions to beexecuted.

In order to improve performance of a DSP, certain instructions may beexecuted in a pipelined fashion, in which multiple instructions areexecuted at the same time by different functional units of the DSP.However, particularly with respect to imperfectly nested loops,executing such nested loops in a pipelined fashion introducesdifficulties in determining whether to execute an instruction associatedwith the one or more outer loops, for example determining a predicatefor the instruction in an efficient manner.

Examples of the present disclosure that address the foregoing include anested loop controller that maintains an inner loop counter, an outerloop counter, and a predicate first-in, first-out buffer (FIFO) toimprove pipelined execution of nested loops. Other examples includeinstructions for initializing the nested loop controller, controllingthe nested loop controller during execution of a nested loop, andaccessing the predicate FIFO during execution of a nested loop todetermine whether a predicated instruction is executed in a particularcycle. Still other examples are directed to a compiler configured tocompile a nested loop to leverage the functionality of the nested loopcontroller and associated instructions explained above.

FIG. 1 illustrates a dual scalar/vector datapath processor in accordancewith various examples of this disclosure. Processor 100 includesseparate level one instruction cache (L1I) 121 and level one data cache(L1D) 123. Processor 100 includes a level two combined instruction/datacache (L2) 130 that holds both instructions and data. FIG. 1 illustratesconnection between level one instruction cache 121 and level twocombined instruction/data cache 130 (bus 142). FIG. 1 illustratesconnection between level one data cache 123 and level two combinedinstruction/data cache 130 (bus 145). In an example, processor 100 leveltwo combined instruction/data cache 130 stores both instructions to backup level one instruction cache 121 and data to back up level one datacache 123. In this example, level two combined instruction/data cache130 is further connected to higher level cache and/or main memory in amanner known in the art and not illustrated in FIG. 1. In this example,central processing unit core 110, level one instruction cache 121, levelone data cache 123 and level two combined instruction/data cache 130 areformed on a single integrated circuit. This signal integrated circuitoptionally includes other circuits.

Central processing unit core 110 fetches instructions from level oneinstruction cache 121 as controlled by instruction fetch unit 111.Instruction fetch unit 111 determines the next instructions to beexecuted and recalls a fetch packet sized set of such instructions. Thenature and size of fetch packets are further detailed below. As known inthe art, instructions are directly fetched from level one instructioncache 121 upon a cache hit (if these instructions are stored in levelone instruction cache 121). Upon a cache miss (the specified instructionfetch packet is not stored in level one instruction cache 121), theseinstructions are sought in level two combined cache 130. In thisexample, the size of a cache line in level one instruction cache 121equals the size of a fetch packet. The memory locations of theseinstructions are either a hit in level two combined cache 130 or a miss.A hit is serviced from level two combined cache 130. A miss is servicedfrom a higher level of cache (not illustrated) or from main memory (notillustrated). As is known in the art, the requested instruction may besimultaneously supplied to both level one instruction cache 121 andcentral processing unit core 110 to speed use.

In an example, central processing unit core 110 includes pluralfunctional units to perform instruction specified data processing tasks.Instruction dispatch unit 112 determines the target functional unit ofeach fetched instruction. In this example, central processing unit 110operates as a very long instruction word (VLIW) processor capable ofoperating on plural instructions in corresponding functional unitssimultaneously. Preferably a complier organizes instructions in executepackets that are executed together. Instruction dispatch unit 112directs each instruction to its target functional unit. The functionalunit assigned to an instruction is completely specified by theinstruction produced by a compiler. The hardware of central processingunit core 110 has no part in this functional unit assignment. In thisexample, instruction dispatch unit 112 may operate on pluralinstructions in parallel. The number of such parallel instructions isset by the size of the execute packet. This will be further detailedbelow.

One part of the dispatch task of instruction dispatch unit 112 isdetermining whether the instruction is to execute on a functional unitin scalar datapath side A 115 or vector datapath side B 116. Aninstruction bit within each instruction called the s bit determineswhich datapath the instruction controls. This will be further detailedbelow.

Instruction decode unit 113 decodes each instruction in a currentexecute packet. Decoding includes identification of the functional unitperforming the instruction, identification of registers used to supplydata for the corresponding data processing operation from among possibleregister files and identification of the register destination of theresults of the corresponding data processing operation. As furtherexplained below, instructions may include a constant field in place ofone register number operand field. The result of this decoding issignals for control of the target functional unit to perform the dataprocessing operation specified by the corresponding instruction on thespecified data.

Central processing unit core 110 includes control registers 114. Controlregisters 114 store information for control of the functional units inscalar datapath side A 115 and vector datapath side B 116. Thisinformation could be mode information or the like.

The decoded instructions from instruction decode 113 and informationstored in control registers 114 are supplied to scalar datapath side A115 and vector datapath side B 116. As a result functional units withinscalar datapath side A 115 and vector datapath side B 116 performinstruction specified data processing operations upon instructionspecified data and store the results in an instruction specified dataregister or registers. Each of scalar datapath side A 115 and vectordatapath side B 116 includes plural functional units that preferablyoperate in parallel. These will be further detailed below in conjunctionwith FIG. 2. There is a datapath 117 between scalar datapath side A 115and vector datapath side B 116 permitting data exchange.

Central processing unit core 110 includes further non-instruction basedmodules. Emulation unit 118 permits determination of the machine stateof central processing unit core 110 in response to instructions. Thiscapability will typically be employed for algorithmic development.Interrupts/exceptions unit 119 enables central processing unit core 110to be responsive to external, asynchronous events (interrupts) and torespond to attempts to perform improper operations (exceptions).

Central processing unit core 110 includes streaming engine 125.Streaming engine 125 of this illustrated embodiment supplies two datastreams from predetermined addresses typically cached in level twocombined cache 130 to register files of vector datapath side B 116. Thisprovides controlled data movement from memory (as cached in level twocombined cache 130) directly to functional unit operand inputs. This isfurther detailed below.

FIG. 1 illustrates exemplary data widths of busses between variousparts. Level one instruction cache 121 supplies instructions toinstruction fetch unit 111 via bus 141. Bus 141 is preferably a 512-bitbus. Bus 141 is unidirectional from level one instruction cache 121 tocentral processing unit 110. Level two combined cache 130 suppliesinstructions to level one instruction cache 121 via bus 142. Bus 142 ispreferably a 512-bit bus. Bus 142 is unidirectional from level twocombined cache 130 to level one instruction cache 121.

Level one data cache 123 exchanges data with register files in scalardatapath side A 115 via bus 143. Bus 143 is preferably a 64-bit bus.Level one data cache 123 exchanges data with register files in vectordatapath side B 116 via bus 144. Bus 144 is preferably a 512-bit bus.Busses 143 and 144 are illustrated as bidirectional supporting bothcentral processing unit 110 data reads and data writes. Level one datacache 123 exchanges data with level two combined cache 130 via bus 145.Bus 145 is preferably a 512-bit bus. Bus 145 is illustrated asbidirectional supporting cache service for both central processing unit110 data reads and data writes.

As known in the art, CPU data requests are directly fetched from levelone data cache 123 upon a cache hit (if the requested data is stored inlevel one data cache 123). Upon a cache miss (the specified data is notstored in level one data cache 123), this data is sought in level twocombined cache 130. The memory locations of this requested data iseither a hit in level two combined cache 130 or a miss. A hit isserviced from level two combined cache 130. A miss is serviced fromanother level of cache (not illustrated) or from main memory (notillustrated). As is known in the art, the requested instruction may besimultaneously supplied to both level one data cache 123 and centralprocessing unit core 110 to speed use.

Level two combined cache 130 supplies data of a first data stream tostreaming engine 125 via bus 146. Bus 146 is preferably a 512-bit bus.Streaming engine 125 supplies data of this first data stream tofunctional units of vector datapath side B 116 via bus 147. Bus 147 ispreferably a 512-bit bus. Level two combined cache 130 supplies data ofa second data stream to streaming engine 125 via bus 148. Bus 148 ispreferably a 512-bit bus. Streaming engine 125 supplies data of thissecond data stream to functional units of vector datapath side B 116 viabus 149. Bus 149 is preferably a 512-bit bus. Busses 146, 147, 148 and149 are illustrated as unidirectional from level two combined cache 130to streaming engine 125 and to vector datapath side B 116 in accordancewith various examples of this disclosure.

Streaming engine 125 data requests are directly fetched from level twocombined cache 130 upon a cache hit (if the requested data is stored inlevel two combined cache 130). Upon a cache miss (the specified data isnot stored in level two combined cache 130), this data is sought fromanother level of cache (not illustrated) or from main memory (notillustrated). It is technically feasible in some examples for level onedata cache 123 to cache data not stored in level two combined cache 130.If such operation is supported, then upon a streaming engine 125 datarequest that is a miss in level two combined cache 130, level twocombined cache 130 should snoop level one data cache 123 for the streamengine 125 requested data. If level one data cache 123 stores this dataits snoop response would include the data, which is then supplied toservice the streaming engine 125 request. If level one data cache 123does not store this data its snoop response would indicate this andlevel two combined cache 130 must service this streaming engine 125request from another level of cache (not illustrated) or from mainmemory (not illustrated).

In an example, both level one data cache 123 and level two combinedcache 130 may be configured as selected amounts of cache or directlyaddressable memory in accordance with U.S. Pat. No. 6,606,686 entitledUNIFIED MEMORY SYSTEM ARCHITECTURE INCLUDING CACHE AND DIRECTLYADDRESSABLE STATIC RANDOM ACCESS MEMORY.

FIG. 2 illustrates further details of functional units and registerfiles within scalar datapath side A 115 and vector datapath side B 116.Scalar datapath side A 115 includes global scalar register file 211,L1/S1 local register file 212, M1/N1 local register file 213 and D1/D2local register file 214. Scalar datapath side A 115 includes L1 unit221, S1 unit 222, M1 unit 223, N1 unit 224, D1 unit 225 and D2 unit 226.Vector datapath side B 116 includes global vector register file 231,L2/S2 local register file 232, M2/N2/C local register file 233 andpredicate register file 234. Vector datapath side B 116 includes L2 unit241, S2 unit 242, M2 unit 243, N2 unit 244, C unit 245 and P unit 246.There are limitations upon which functional units may read from or writeto which register files. These will be detailed below.

Scalar datapath side A 115 includes L1 unit 221. L1 unit 221 generallyaccepts two 64-bit operands and produces one 64-bit result. The twooperands are each recalled from an instruction specified register ineither global scalar register file 211 or L1/S1 local register file 212.L1 unit 221 preferably performs the following instruction selectedoperations: 64-bit add/subtract operations; 32-bit min/max operations;8-bit Single Instruction Multiple Data (SIMD) instructions such as sumof absolute value, minimum and maximum determinations; circular min/maxoperations; and various move operations between register files. Theresult may be written into an instruction specified register of globalscalar register file 211, L1/S1 local register file 212, M1/N1 localregister file 213 or D1/D2 local register file 214.

Scalar datapath side A 115 includes S1 unit 222. S1 unit 222 generallyaccepts two 64-bit operands and produces one 64-bit result. The twooperands are each recalled from an instruction specified register ineither global scalar register file 211 or L1/S1 local register file 212.S1 unit 222 preferably performs the same type operations as L1 unit 221.There optionally may be slight variations between the data processingoperations supported by L1 unit 221 and S1 unit 222. The result may bewritten into an instruction specified register of global scalar registerfile 211, L1/S1 local register file 212, M1/N1 local register file 213or D1/D2 local register file 214.

Scalar datapath side A 115 includes M1 unit 223. M1 unit 223 generallyaccepts two 64-bit operands and produces one 64-bit result. The twooperands are each recalled from an instruction specified register ineither global scalar register file 211 or M1/N1 local register file 213.M1 unit 223 preferably performs the following instruction selectedoperations: 8-bit multiply operations; complex dot product operations;32-bit bit count operations; complex conjugate multiply operations; andbit-wise Logical Operations, moves, adds and subtracts. The result maybe written into an instruction specified register of global scalarregister file 211, L1/S1 local register file 212, M1/N1 local registerfile 213 or D1/D2 local register file 214.

Scalar datapath side A 115 includes N1 unit 224. N1 unit 224 generallyaccepts two 64-bit operands and produces one 64-bit result. The twooperands are each recalled from an instruction specified register ineither global scalar register file 211 or M1/N1 local register file 213.N1 unit 224 preferably performs the same type operations as M1 unit 223.There may be certain double operations (called dual issued instructions)that employ both the M1 unit 223 and the N1 unit 224 together. Theresult may be written into an instruction specified register of globalscalar register file 211, L1/S1 local register file 212, M1/N1 localregister file 213 or D1/D2 local register file 214.

Scalar datapath side A 115 includes D1 unit 225 and D2 unit 226. D1 unit225 and D2 unit 226 generally each accept two 64-bit operands and eachproduce one 64-bit result. D1 unit 225 and D2 unit 226 generally performaddress calculations and corresponding load and store operations. D1unit 225 is used for scalar loads and stores of 64 bits. D2 unit 226 isused for vector loads and stores of 512 bits. D1 unit 225 and D2 unit226 preferably also perform: swapping, pack and unpack on the load andstore data; 64-bit SIMD arithmetic operations; and 64-bit bit-wiselogical operations. D1/D2 local register file 214 will generally storebase and offset addresses used in address calculations for thecorresponding loads and stores. The two operands are each recalled froman instruction specified register in either global scalar register file211 or D1/D2 local register file 214. The calculated result may bewritten into an instruction specified register of global scalar registerfile 211, L1/S1 local register file 212, M1/N1 local register file 213or D1/D2 local register file 214.

Vector datapath side B 116 includes L2 unit 241. L2 unit 241 generallyaccepts two 512-bit operands and produces one 512-bit result. The twooperands are each recalled from an instruction specified register ineither global vector register file 231, L2/S2 local register file 232 orpredicate register file 234. L2 unit 241 preferably performs instructionsimilar to L1 unit 221 except on wider 512-bit data. The result may bewritten into an instruction specified register of global vector registerfile 231, L2/S2 local register file 232, M2/N2/C local register file 233or predicate register file 234.

Vector datapath side B 116 includes S2 unit 242. S2 unit 242 generallyaccepts two 512-bit operands and produces one 512-bit result. The twooperands are each recalled from an instruction specified register ineither global vector register file 231, L2/S2 local register file 232 orpredicate register file 234. S2 unit 242 preferably performsinstructions similar to S1 unit 222. The result may be written into aninstruction specified register of global vector register file 231, L2/S2local register file 232, M2/N2/C local register file 233 or predicateregister file 234.

Vector datapath side B 116 includes M2 unit 243. M2 unit 243 generallyaccepts two 512-bit operands and produces one 512-bit result. The twooperands are each recalled from an instruction specified register ineither global vector register file 231 or M2/N2/C local register file233. M2 unit 243 preferably performs instructions similar to M1 unit 223except on wider 512-bit data. The result may be written into aninstruction specified register of global vector register file 231, L2/S2local register file 232 or M2/N2/C local register file 233.

Vector datapath side B 116 includes N2 unit 244. N2 unit 244 generallyaccepts two 512-bit operands and produces one 512-bit result. The twooperands are each recalled from an instruction specified register ineither global vector register file 231 or M2/N2/C local register file233. N2 unit 244 preferably performs the same type operations as M2 unit243. There may be certain double operations (called dual issuedinstructions) that employ both M2 unit 243 and the N2 unit 244 together.The result may be written into an instruction specified register ofglobal vector register file 231, L2/S2 local register file 232 orM2/N2/C local register file 233.

Vector datapath side B 116 includes C unit 245. C unit 245 generallyaccepts two 512-bit operands and produces one 512-bit result. The twooperands are each recalled from an instruction specified register ineither global vector register file 231 or M2/N2/C local register file233. C unit 245 preferably performs: “Rake” and “Search” instructions;up to 512 2-bit PN*8-bit multiplies I/Q complex multiplies per clockcycle; 8-bit and 16-bit Sum-of-Absolute-Difference (SAD) calculations,up to 512 SADs per clock cycle; horizontal add and horizontal min/maxinstructions; and vector permutes instructions. C unit 245 also contains4 vector control registers (CUCR0 to CUCR3) used to control certainoperations of C unit 245 instructions. Control registers CUCR0 to CUCR3are used as operands in certain C unit 245 operations. Control registersCUCR0 to CUCR3 are preferably used: in control of a general permutationinstruction (VPERM); and as masks for SIMD multiple DOT productoperations (DOTPM) and SIMD multiple Sum-of-Absolute-Difference (SAD)operations. Control register CUCR0 is preferably used to store thepolynomials for Galois Field Multiply operations (GFMPY). Controlregister CUCR1 is preferably used to store the Galois field polynomialgenerator function.

Vector datapath side B 116 includes P unit 246. P unit 246 performsbasic logic operations on registers of local predicate register file234. P unit 246 has direct access to read from and write to predicationregister file 234. These operations include single register unaryoperations such as: NEG (negate) which inverts each bit of the singleregister; BITCNT (bit count) which returns a count of the number of bitsin the single register having a predetermined digital state (1 or 0);RMBD (right most bit detect) which returns a number of bit positionsfrom the least significant bit position (right most) to a first bitposition having a predetermined digital state (1 or 0); DECIMATE whichselects every instruction specified Nth (1, 2, 4, etc.) bit to output;and EXPAND which replicates each bit an instruction specified N times(2, 4, etc.). These operations include two register binary operationssuch as: AND a bitwise AND of data of the two registers; NAND a bitwiseAND and negate of data of the two registers; OR a bitwise OR of data ofthe two registers; NOR a bitwise OR and negate of data of the tworegisters; and XOR exclusive OR of data of the two registers. Theseoperations include transfer of data from a predicate register ofpredicate register file 234 to another specified predicate register orto a specified data register in global vector register file 231. Acommonly expected use of P unit 246 includes manipulation of the SIMDvector comparison results for use in control of a further SIMD vectoroperation. The BITCNT instruction may be used to count the number of 1'sin a predicate register to determine the number of valid data elementsfrom a predicate register.

FIG. 3 illustrates global scalar register file 211. There are 16independent 64-bit wide scalar registers designated A0 to A15. Eachregister of global scalar register file 211 can be read from or writtento as 64-bits of scalar data. All scalar datapath side A 115 functionalunits (L1 unit 221, S1 unit 222, M1 unit 223, N1 unit 224, D1 unit 225and D2 unit 226) can read or write to global scalar register file 211.Global scalar register file 211 may be read as 32-bits or as 64-bits andmay only be written to as 64-bits. The instruction executing determinesthe read data size. Vector datapath side B 116 functional units (L2 unit241, S2 unit 242, M2 unit 243, N2 unit 244, C unit 245 and P unit 246)can read from global scalar register file 211 via crosspath 117 underrestrictions that will be detailed below.

FIG. 4 illustrates D1/D2 local register file 214. There are 16independent 64-bit wide scalar registers designated D0 to D16. Eachregister of D1/D2 local register file 214 can be read from or written toas 64-bits of scalar data. All scalar datapath side A 115 functionalunits (L1 unit 221, S1 unit 222, M1 unit 223, N1 unit 224, D1 unit 225and D2 unit 226) can write to global scalar register file 211. Only D1unit 225 and D2 unit 226 can read from D1/D2 local scalar register file214. It is expected that data stored in D1/D2 local scalar register file214 will include base addresses and offset addresses used in addresscalculation.

FIG. 5 illustrates L1/S1 local register file 212. The exampleillustrated in FIG. 5 has 8 independent 64-bit wide scalar registersdesignated AL0 to AL7. The preferred instruction coding (see FIG. 15)permits L1/S1 local register file 212 to include up to 16 registers. Theexample of FIG. 5 implements only 8 registers to reduce circuit size andcomplexity. Each register of L1/S1 local register file 212 can be readfrom or written to as 64-bits of scalar data. All scalar datapath side A115 functional units (L1 unit 221, S1 unit 222, M1 unit 223, N1 unit224, D1 unit 225 and D2 unit 226) can write to L1/S1 local scalarregister file 212. Only L1 unit 221 and S1 unit 222 can read from L1/S1local scalar register file 212.

FIG. 6 illustrates M1/N1 local register file 213. The exampleillustrated in FIG. 6 has 8 independent 64-bit wide scalar registersdesignated AM0 to AM7. The preferred instruction coding (see FIG. 15)permits M1/N1 local register file 213 to include up to 16 registers. Theexample of FIG. 6 implements only 8 registers to reduce circuit size andcomplexity. Each register of M1/N1 local register file 213 can be readfrom or written to as 64-bits of scalar data. All scalar datapath side A115 functional units (L1 unit 221, S1 unit 222, M1 unit 223, N1 unit224, D1 unit 225 and D2 unit 226) can write to M1/N1 local scalarregister file 213. Only M1 unit 223 and N1 unit 224 can read from M1/N1local scalar register file 213.

FIG. 7 illustrates global vector register file 231. There are 16independent 512-bit wide vector registers. Each register of globalvector register file 231 can be read from or written to as 64-bits ofscalar data designated B0 to B15. Each register of global vectorregister file 231 can be read from or written to as 512-bits of vectordata designated VB0 to VB15. The instruction type determines the datasize. All vector datapath side B 116 functional units (L2 unit 241, S2unit 242, M2 unit 243, N2 unit 244, C unit 245 and P unit 246) can reador write to global scalar register file 231. Scalar datapath side A 115functional units (L1 unit 221, S1 unit 222, M1 unit 223, N1 unit 224, D1unit 225 and D2 unit 226) can read from global vector register file 231via crosspath 117 under restrictions that will be detailed below.

FIG. 8 illustrates P local register file 234. There are 8 independent64-bit wide registers designated P0 to P7. Each register of P localregister file 234 can be read from or written to as 64-bits of scalardata. Vector datapath side B 116 functional units L2 unit 241, S2 unit242, C unit 244 and P unit 246 can write to P local register file 234.Only L2 unit 241, S2 unit 242 and P unit 246 can read from P localscalar register file 234. A commonly expected use of P local registerfile 234 includes: writing one bit SIMD vector comparison results fromL2 unit 241, S2 unit 242 or C unit 244; manipulation of the SIMD vectorcomparison results by P unit 246; and use of the manipulated results incontrol of a further SIMD vector operation.

FIG. 9 illustrates L2/S2 local register file 232. The exampleillustrated in FIG. 9 has 8 independent 512-bit wide vector registers.The preferred instruction coding (see FIG. 15) permits L2/S2 localregister file 232 to include up to 16 registers. The example of FIG. 9implements only 8 registers to reduce circuit size and complexity. Eachregister of L2/S2 local vector register file 232 can be read from orwritten to as 64-bits of scalar data designated BL0 to BL7. Eachregister of L2/S2 local vector register file 232 can be read from orwritten to as 512-bits of vector data designated VBL0 to VBL7. Theinstruction type determines the data size. All vector datapath side B116 functional units (L2 unit 241, S2 unit 242, M2 unit 243, N2 unit244, C unit 245 and P unit 246) can write to L2/S2 local vector registerfile 232. Only L2 unit 241 and S2 unit 242 can read from L2/S2 localvector register file 232.

FIG. 10 illustrates M2/N2/C local register file 233. The exampleillustrated in FIG. 10 has 8 independent 512-bit wide vector registers.The preferred instruction coding (see FIG. 15) permits M2/N2/C localvector register file 233 include up to 16 registers. The example of FIG.10 implements only 8 registers to reduce circuit size and complexity.Each register of M2/N2/C local vector register file 233 can be read fromor written to as 64-bits of scalar data designated BM0 to BM7. Eachregister of M2/N2/C local vector register file 233 can be read from orwritten to as 512-bits of vector data designated VBM0 to VBM7. Allvector datapath side B 116 functional units (L2 unit 241, S2 unit 242,M2 unit 243, N2 unit 244, C unit 245 and P unit 246) can write toM2/N2/C local vector register file 233. Only M2 unit 243, N2 unit 244and C unit 245 can read from M2/N2/C local vector register file 233.

The provision of global register files accessible by all functionalunits of a side and local register files accessible by only some of thefunctional units of a side is a design choice. Some examples of thisdisclosure employ only one type of register file corresponding to thedisclosed global register files.

Referring back to FIG. 2, crosspath 117 permits limited exchange of databetween scalar datapath side A 115 and vector datapath side B 116.During each operational cycle one 64-bit data word can be recalled fromglobal scalar register file A 211 for use as an operand by one or morefunctional units of vector datapath side B 116 and one 64-bit data wordcan be recalled from global vector register file 231 for use as anoperand by one or more functional units of scalar datapath side A 115.Any scalar datapath side A 115 functional unit (L1 unit 221, S1 unit222, M1 unit 223, N1 unit 224, D1 unit 225 and D2 unit 226) may read a64-bit operand from global vector register file 231. This 64-bit operandis the least significant bits of the 512-bit data in the accessedregister of global vector register file 231. Plural scalar datapath sideA 115 functional units may employ the same 64-bit crosspath data as anoperand during the same operational cycle. However, only one 64-bitoperand is transferred from vector datapath side B 116 to scalardatapath side A 115 in any single operational cycle. Any vector datapathside B 116 functional unit (L2 unit 241, S2 unit 242, M2 unit 243, N2unit 244, C unit 245 and P unit 246) may read a 64-bit operand fromglobal scalar register file 211. If the corresponding instruction is ascalar instruction, the crosspath operand data is treated as any other64-bit operand. If the corresponding instruction is a vectorinstruction, the upper 448 bits of the operand are zero filled. Pluralvector datapath side B 116 functional units may employ the same 64-bitcrosspath data as an operand during the same operational cycle. Only one64-bit operand is transferred from scalar datapath side A 115 to vectordatapath side B 116 in any single operational cycle.

Streaming engine 125 transfers data in certain restricted circumstances.Streaming engine 125 controls two data streams. A stream consists of asequence of elements of a particular type. Programs that operate onstreams read the data sequentially, operating on each element in turn.Every stream has the following basic properties. The stream data have awell-defined beginning and ending in time. The stream data have fixedelement size and type throughout the stream. The stream data have afixed sequence of elements. Thus, programs cannot seek randomly withinthe stream. The stream data is read-only while active. Programs cannotwrite to a stream while simultaneously reading from it. Once a stream isopened, the streaming engine 125: calculates the address; fetches thedefined data type from level two unified cache (which may require cacheservice from a higher level memory); performs data type manipulationsuch as zero extension, sign extension, data element sorting/swappingsuch as matrix transposition; and delivers the data directly to theprogrammed data register file within CPU 110. Streaming engine 125 isthus useful for real-time digital filtering operations on well-behaveddata. Streaming engine 125 frees these memory fetch tasks from thecorresponding CPU enabling other processing functions.

Streaming engine 125 provides the following benefits. Streaming engine125 permits multi-dimensional memory accesses. Streaming engine 125increases the available bandwidth to the functional units. Streamingengine 125 minimizes the number of cache miss stalls since the streambuffer bypasses level one data cache 123. Streaming engine 125 reducesthe number of scalar operations required to maintain a loop. Streamingengine 125 manages address pointers. Streaming engine 125 handlesaddress generation automatically freeing up the address generationinstruction slots and D1 unit 225 and D2 unit 226 for othercomputations.

CPU 110 operates on an instruction pipeline. Instructions are fetched ininstruction packets of fixed length further described below. Allinstructions require the same number of pipeline phases for fetch anddecode, but require a varying number of execute phases.

FIG. 11 illustrates the following pipeline phases: program fetch phase1110, dispatch and decode phases 1120 and execution phases 1130. Programfetch phase 1110 includes three stages for all instructions. Dispatchand decode phases 1120 include three stages for all instructions.Execution phase 1130 includes one to four stages dependent on theinstruction.

Fetch phase 1110 includes program address generation stage 1111 (PG),program access stage 1112 (PA) and program receive stage 1113 (PR).During program address generation stage 1111 (PG), the program addressis generated in the CPU and the read request is sent to the memorycontroller for the level one instruction cache L1I. During the programaccess stage 1112 (PA) the level one instruction cache L1I processes therequest, accesses the data in its memory and sends a fetch packet to theCPU boundary. During the program receive stage 1113 (PR) the CPUregisters the fetch packet.

Instructions are always fetched sixteen 32-bit wide slots, constitutinga fetch packet, at a time. FIG. 12 illustrates 16 instructions 1201 to1216 of a single fetch packet. Fetch packets are aligned on 512-bit(16-word) boundaries. An example employs a fixed 32-bit instructionlength. Fixed length instructions are advantageous for several reasons.Fixed length instructions enable easy decoder alignment. A properlyaligned instruction fetch can load plural instructions into parallelinstruction decoders. Such a properly aligned instruction fetch can beachieved by predetermined instruction alignment when stored in memory(fetch packets aligned on 512-bit boundaries) coupled with a fixedinstruction packet fetch. An aligned instruction fetch permits operationof parallel decoders on instruction-sized fetched bits. Variable lengthinstructions require an initial step of locating each instructionboundary before they can be decoded. A fixed length instruction setgenerally permits more regular layout of instruction fields. Thissimplifies the construction of each decoder which is an advantage for awide issue VLIW central processor.

The execution of the individual instructions is partially controlled bya p bit in each instruction. This p bit is preferably bit 0 of the32-bit wide slot. The p bit determines whether an instruction executesin parallel with a next instruction. Instructions are scanned from lowerto higher address. If the p bit of an instruction is 1, then the nextfollowing instruction (higher memory address) is executed in parallelwith (in the same cycle as) that instruction. If the p bit of aninstruction is 0, then the next following instruction is executed in thecycle after the instruction.

CPU 110 and level one instruction cache L1I 121 pipelines are de-coupledfrom each other. Fetch packet returns from level one instruction cacheL1I can take different number of clock cycles, depending on externalcircumstances such as whether there is a hit in level one instructioncache 121 or a hit in level two combined cache 130. Therefore programaccess stage 1112 (PA) can take several clock cycles instead of 1 clockcycle as in the other stages.

The instructions executing in parallel constitute an execute packet. Inan example, an execute packet can contain up to sixteen instructions. Notwo instructions in an execute packet may use the same functional unit.A slot is one of five types: 1) a self-contained instruction executed onone of the functional units of CPU 110 (L1 unit 221, S1 unit 222, M1unit 223, N1 unit 224, D1 unit 225, D2 unit 226, L2 unit 241, S2 unit242, M2 unit 243, N2 unit 244, C unit 245 and P unit 246); 2) a unitlessinstruction such as a NOP (no operation) instruction or multiple NOPinstruction; 3) a branch instruction; 4) a constant field extension; and5) a conditional code extension. Some of these slot types will befurther explained below.

Dispatch and decode phases 1120 include instruction dispatch toappropriate execution unit stage 1121 (DS), instruction pre-decode stage1122 (DC1); and instruction decode, operand reads stage 1123 (DC2).During instruction dispatch to appropriate execution unit stage 1121(DS), the fetch packets are split into execute packets and assigned tothe appropriate functional units. During the instruction pre-decodestage 1122 (DC1), the source registers, destination registers andassociated paths are decoded for the execution of the instructions inthe functional units. During the instruction decode, operand reads stage1123 (DC2), more detailed unit decodes are done, as well as readingoperands from the register files.

Execution phases 1130 includes execution stages 1131 to 1135 (E1 to E5).Different types of instructions require different numbers of thesestages to complete their execution. These stages of the pipeline play animportant role in understanding the device state at CPU cycleboundaries.

During execute 1 stage 1131 (E1) the conditions for the instructions areevaluated and operands are operated on. As illustrated in FIG. 11,execute 1 stage 1131 may receive operands from a stream buffer 1141 andone of the register files shown schematically as 1142. For load andstore instructions, address generation is performed and addressmodifications are written to a register file. For branch instructions,branch fetch packet in PG phase is affected. As illustrated in FIG. 11,load and store instructions access memory here shown schematically asmemory 1151. For single-cycle instructions, results are written to adestination register file. This assumes that any conditions for theinstructions are evaluated as true. If a condition is evaluated asfalse, the instruction does not write any results or have any pipelineoperation after execute 1 stage 1131.

During execute 2 stage 1132 (E2) load instructions send the address tomemory. Store instructions send the address and data to memory.Single-cycle instructions that saturate results set the SAT bit in thecontrol status register (CSR) if saturation occurs. For 2-cycleinstructions, results are written to a destination register file.

During execute 3 stage 1133 (E3) data memory accesses are performed. Anymultiply instructions that saturate results set the SAT bit in thecontrol status register (CSR) if saturation occurs. For 3-cycleinstructions, results are written to a destination register file.

During execute 4 stage 1134 (E4) load instructions bring data to the CPUboundary. For 4-cycle instructions, results are written to a destinationregister file.

During execute 5 stage 1135 (E5) load instructions write data into aregister. This is illustrated schematically in FIG. 11 with input frommemory 1151 to execute 5 stage 1135.

In some cases, the processor 100 (e.g., a DSP) may be called upon toexecute software that includes nested loops. Software pipelininginvolves initiating new iterations of the loop before previousiterations have completed to obtain high throughput. This implies thereare some cycles (loop prolog) to begin executing, or pipe up, of eachinner loop and some more cycles to pipe down the loop (loop epilog).These cycles will be incurred for each outer loop execution so they canaffect performance, especially when the inner loop count is small. Themore deeply pipelined the DSP 100 is, the more cycles will be requiredfor the prolog and epilog. As explained above, particularly with respectto imperfectly nested loops, executing nested loops in a pipelinedfashion introduces difficulties in determining whether to execute aninstruction associated with the one or more outer loops, for exampledetermining a predicate for the instruction in an efficient manner.

In the following description, reference is made to an exemplary nestedloop as follows, with the function of each line of pseudo-code explainedas a comment:

for (int i = 0; i < N; i++) { // outer loop of N iterations  B0 = 0; //initialize register B0 to a value of 0  for (int j = 0; j < M; j++) { //inner loop of M iterations   B0 += D0[i*M + j]; // B0 as a running sumof elements of  }  array D0  D1[i] = B0; // store each M-element }  sumas element of array D1

EXAMPLE 1 Uncoalesced Nested Loop

For terminological consistency, the above nested loop has an “inner loopcount” value of M and an “outer loop count” value of N.

This exemplary nested loop can be rewritten or “coalesced” as a singleloop by conditioning or predicating the instructions associated with theouter loop. An example of the resulting coalesced nested loop is givenas follows:

for (int k = 0; k < N*M; k++) {  if (k % M == 0) B0 = 0; //only executedwhen k-count  corresponds to an outer //loop iteration  B0 += D0[k];  if((k+1) % M == 0) D1[k/M] = B0; //same as above }

EXAMPLE 2a Coalesced Nested Loop

The foregoing is one example of loop coalescing. Other examples mayavoid the more computationally-intensive division and modulus operationsby implementing record-keeping variables and utilizing pointerarithmetic. For example:

Inner count = 0; for (int k = 0; k < N*M; k++) {  if (Inner_count == M){   Inner_count = 0; // reset inner count if M inner  loop iterationsperformed   B0 = 0; // reset accumulator upon re-entry of  }  originalinner loop  B0 += *D0++ //equivalent to B0 += D0[k];  if (++Inner_count== M) *D1++ = B0; }

EXAMPLE 2b Coalesced Nested Loop

In some examples, one or more outer loops may be empty, or not containany instructions other than the loop control instruction itself. Such anouter loop can be combined or collapsed to the next (inside) outer loopby adjusting the variables in the loop control instruction. For example:

  for (int i = 0; i < N; i++) {    for (int j = 0; j < M; j++) {     B0+= D0[i*];    }   }   This may be collapsed to be:   for (int k = 0; k <N*M; k++) {    B0 += D0[k];   }

EXAMPLE 3 Collapsed Nested Loop

Once any such empty outer loops have been collapsed, the resultantimperfectly nested loop is coalesced as explained above.

As will be explained in further detail below, a coalesced nested loop ismore suited to take advantage of pipelined execution of software by theDSP 100. However, since the outer loop instructions are conditioned(e.g., only carried out in the pseudo-code above as a result of an ifstatement being true), the corresponding outer loop instructions in thepipeline must be predicated, which requires that a predicate bedetermined for each instruction to decide whether to execute the outerloop instruction in a particular cycle. Typically, the computation andstorage of predicate values is complex and monopolizes a large number ofregisters (e.g., to hold predicate values for many differentinstructions). Examples of this disclosure directed to the nested loopcontroller, explained further below, improve upon these shortcomings.

Turning now to FIG. 13A, a nested loop controller 1300 is shown inaccordance with examples of this disclosure. The nested loop controller1300 is shown employing hardware and logic constructs, which areexemplary. It should be appreciated that the nested loop controller 1300may be designed using different, substitute hardware and logicconstructs. The nested loop controller 1300 includes an outer loopcounter 1302 (having an OLCNT value), an inner loop counter 1308 (havingan ILCNT value), and a predicate FIFO 1312. Each of the counters 1302,1308 and the predicate FIFO 1312 may be implemented as, for example, aregister, such as control registers 114 explained above. In certainexamples, the nested loop controller 1300 also includes an episkewcounter 1316 (having an EPISKEW value), which may also be implemented asa control register 114 and will be explained in further detail below.

Examples of this disclosure also include instructions to interact with anested loop controller 1300. A nested loop controller 1300initialization instruction (NLCINIT) initializes the outer loop counter1302 and the inner loop counter 1308 (and/or an inner loop reloadregister 1304) values. For the sake of consistency, it is assumed thatNLCINIT initializes the outer loop counter 1302 to the outer loop countvalue minus 1 and initializes the inner loop counter (and/or the innerloop reload register 1304, depending on implementation) to the innerloop count value minus 1. In this particular example, the nested loopcontroller 1300 functions by decrementing counter values, and thus athreshold (e.g., for purposes of resetting) for the counter values iszero. However, it should be appreciated that, more generally, the outerloop, inner loop, and episkew counters 1302, 1308, 1316 are advanced,and could, for example, be initialized to a value of zero andsubsequently incremented to a threshold (e.g., the loop count valueminus 1). This disclosure is not restricted to any particular method ofcounter management, and all such approaches are within the scope of theexamples described herein. A compiler generates an NLCINIT instructionto be executed prior to the instructions of the nested loop.

A nested loop controller 1300 advance instruction (TICK) advances theouter loop, inner loop, and episkew counters 1302, 1308, 1316 of thenested loop controller 1300 according to certain logic, which will beexplained in further detail below. The TICK instruction is a unitlessinstruction. As will also be explained, a compiler generates a TICKinstruction for each iteration of a coalesced nested loop.

A nested loop controller 1300 get predicate instruction (GETP) reads avalue from the predicate FIFO 1312 (e.g., a single bit) and writes thevalue into a destination register of the DSP 100. In addition tospecifying the destination register, a GETP instruction also includes anoffset value that specifies a location in the predicate FIFO 1312 to bewritten into the destination register. As will be explained in furtherdetail below, this allows for a simple approach to accessing thepredicate value associated with a historical TICK instruction. As willbe explained further below, the compiler generates a GETP instructionfor any predicated instructions (i.e., outer loop instructions prior tocoalescing a nested loop), which are then executed depending on thevalue returned by the GETP instruction.

The nested loop controller 1300 functionality will be explained furtherwith reference to FIGS. 13A and 13B and FIGS. 14A-1, 14A-2, 14B, and14C. For simplicity, reference is made to the above nested loop Examples1 and 2, with an outer loop count value (N) of 5, and an inner loopcount value (M) of 3. Further, it is assumed that all instructions arecompleted in one cycle, except a load instruction, which is completed inthree cycles. As explained above, the compiler initially generates anNLCINIT instruction that, when executed, initializes the outer loop andinner loop counters 1302, 1308. In this example, in which counters areadvanced by being decremented, the outer loop counter 1302 isinitialized to the outer loop count value minus 1, or 4, and the innerloop counter 1308 is initialized to the inner loop count value minus 1,or 2. The inner loop reload register 1304 is also initialized to 2 anddoes not change in this example.

A multiplexor (mux) 1306 determines whether to load the inner loopcounter 1308 with the value held in the inner loop reload register 1304(e.g., either as initialization or upon a reset of the inner loopcounter 1308 at the end of an inner loop iteration). A comparator 1310compares the value held in the inner loop counter 1308 to 0 andpopulates the predicate FIFO 1312 accordingly. In this logical example,when the inner loop counter 1308 is equal to 0, a value of 1 is pushedinto the predicate FIFO 1312, which is an outer loop indicator. When theinner loop counter 1308 is not equal to zero, a value of 0 is pushedinto the predicate FIFO 1312, which is an inner loop indicator. Thedistinction and importance of these predicate FIFO 1312 values isexplained further below. A subtraction circuit 1314 decrements the innerloop counter 1308 (in response to execution of a TICK instruction) andupdates the inner loop counter 1308 through the mux 1306.

When the inner loop counter 1308 reaches a threshold (0 in this example)and the outer loop counter 1304 has not yet reached a threshold (again,0 in this example), the inner loop counter 1308 is reset by the mux 1306and the inner loop reload register 1304, while the outer loop counter1302 is decremented. Once the outer loop counter 1302 reaches itsthreshold, the inner loop counter 1208 ceases to be reset. Further,although not demonstrated in the logic of FIGS. 13A and 13B, the outerloop counter 1302 reaching its threshold also prevents the comparator1310 from pushing outer loop indicators (i.e., 1s in this example) intothe predicate FIFO 1312 even though the inner loop counter 1308 is equalto 0. Finally, the episkew counter 1316 is utilized in cases where theone or more stages of the epilog are collapsed.

FIG. 13B shows another example of a nested loop controller 1350 inaccordance with examples of this disclosure. The nested loop controller1350 is similar to the nested loop controller 1300 of FIG. 13A, but withadditional detail shown. For example, the nested loop controller 1350also includes the outer loop counter 1302 and the inner loop counter1308 (and/or an inner loop reload register 1304). The predicate FIFO1312 is also shown in further detail, which demonstrates one example ofhow indexing into the predicate FIFO 1312 is achieved in response to aGETP instruction. In particular, an offset value of a GETP instructioncontrols a mux 1352 to output the desired value of offset into thepredicate FIFO 1312. For example, a GETP instruction having an offsetvalue of 0 and a level value of 0 controls the mux 1352 to select thebit of the predicate FIFO 1312 corresponding to an offset of 0, shown asOffset=0. As another example, a GETP instruction having an offset valueof 3 and a level value of 0 controls the mux 1352 to select the bit ofthe predicate FIFO 1312 corresponding to an offset of 3, shown asOffset=3.

The nested loop controller 1350 includes an additional predicate FIFO1353, which is populated based on whether the outer loop counter 1302 isequal to zero (e.g., based on a comparator 1355). In this example, theouter loop counter 1302 is alternately referred to as a middle loopcounter 1302. A separate outer loop counter, which is not shown forsimplicity, is implemented to indicate when the nested loop controller1350 is to cease executing the coalesced loop (e.g., when the inner,middle, and outer loop counters reach 0 in the example where countersare advanced by being decremented). In particular, having two predicateFIFOs 1312, 1353 as shown allows coalescing nested loops that includeinner, middle, and outer loops that all contain instructions to beexecuted. In this example, the predicate FIFO 1312 provides predicatesfor conditional execution of instructions in the middle loop, while thepredicate FIFO 1353 provides predicates for conditional execution ofinstructions in the outer loop. The predicate FIFO 1353 is also indexedinto using a GETP instruction offset value as a control signal to a mux1354. In addition, a GETP instruction level value is provided as acontrol signal to a mux 1356 to select whether a particular offsetpredicate value is provided by the predicate FIFO 1312 populated basedon the inner loop counter 1308 or the predicate FIFO 1353 populatedbased on the middle loop counter 1302. Regardless of whether a predicatevalue is provided by the predicate FIFO 1312 populated based on theinner loop counter 1308 or the predicate FIFO 1353 populated based onthe middle loop counter 1302, the predicate value is provided to aregister 1357 specified by a GETP instruction, the value of whichregister may then be used to determine whether to execute a predicatedinstruction.

Additionally, the nested loop controller 1350 demonstrates differentways in which the inner loop counter 1308 and the outer loop counter1302 may be populated. For example, based on control of a mux 1358, theinner loop counter 1308 is either populated with a decremented valuefrom the subtraction circuit 1314 (e.g. when the inner loop counter 1308and the outer loop counter 1302 are non-zero) or with an inner loopreload register 1304 value (e.g., when the inner loop counter 1308reaches zero and the outer loop counter 1302 is non-zero). The innerloop counter 1308 may also be initially populated with a valuecorresponding to a move constant (MVC) instruction, which is also usedto initialize the inner loop reload register 1304.

In another example, based on control of a mux 1360, the outer loopcounter 1302 is either populated with a decremented value from asubtraction circuit 1362 (e.g. when the inner loop counter 1308 reacheszero and the outer loop counter 1302 is non-zero) or with the currentvalue in the outer loop counter 1302 (e.g., when the inner loop counter1308 and the outer loop counter 1302 are non-zero). The outer loopcounter 1302 may also be initially populated with a value correspondingto a move constant (MVC) instruction.

As above, the nested loop controller 1350 is initialized with an NLCINITinstruction that initializes both the inner loop counter 1308 and theouter loop counter 1302 registers, as well as provides an episkewparameter that indicates the number of additional branches taken oncethe inner loop counter 1308 and the outer loop counter 1302 reach zero.

Also, as above, the nested loop controller 1350 is advanced in responseto a TICK instruction, which advances the inner loop counter 1308 andthe outer loop counter and updates the predicate FIFOs 1312, 1353. Inone example, the counters 1308, 1302 are advanced “odometer style,” inwhich the inner loop counter 1308 reaching its trip count (e.g., zero)causes the outer loop counter 1302 to advance (e.g., decrement). In someexamples, it is assumed that a TICK instruction is the first instructionin a software pipelined loop.

Further, as above, the nested loop controller 1350 predicate FIFOs 1312,1353 are accessed in response to a GETP instruction. The GETPinstruction provides a nested loop controller 1350 query that retrievesa predicate value for a specified level. In a given iteration of a loop,retrieving the predicate prior to a TICK instruction produces thepreloop predicate (e.g., the predicate register value for the preloopinstructions), while retrieving the predicate following a TICKinstruction produces the postloop predicate (e.g., the predicateregister value for the postloop instructions). In one example, a GETPissued after initialization (e.g., execution of an NLCINIT instruction)but prior to the first TICK returns “true” or an asserted predicatevalue. Such a GETP instruction corresponds to a preloop predicate, sothis exemplary behavior enables preloop instructions to execute on thefirst loop iteration.

The GETP instruction also includes a level parameter that specifies theloop level (e.g., is a control signal for the mux 1356) as explainedabove. The GETP instruction offset value is used as a control signal tothe muxes 1352, 1354 to index into the predicate FIFOs 1312, 1353, whichfacilitates overlapping lifetimes in a software pipeline. In oneexample, unlike a move constant (MVC) instruction, the GETP instructioncan be executed on the .S1, .L1, and .M1 units, instead of only on the.S1 unit.

FIGS. 14A-1 and 14A-2 show an example of pseudo-assembly codeinstructions that result from compiling the coalesced nested loop inaccordance with examples of this disclosure. In particular, FIGS. 14A-1and 14A-2 show a coalesced loop that is not software pipelined, but thatuses the nested loop controller 1300, 1350 described above. The loop ofFIGS. 14A-1 and 14A-2 corresponds to the loops shown in Examples 1 and2, above. The loop of FIGS. 14A-1 and 14A-2 contains an inner loop thatsums part of a vector. An outer loop initializes an accumulator to zerobefore the inner loop. Upon completion of the inner loop, the outer loopstores the accumulation result to memory. Thus, when the nested loop iscoalesced, the outer loop operations need to be predicatedappropriately. A GETP instruction is used to generate a predicate forthe accumulator initialization and another GETP instruction is used togenerate a predicate for the store to memory of the accumulation result.

The vertical axis represents a cycle count and shows which instructionsare executed each cycle. The horizontal axis “slots” represent thefunctional units that carry out a particular instruction, and thusdepicts the instructions executing on particular functional units. Inthis example, a new iteration of the coalesced loop begins every 8cycles.

FIGS. 14A-1 and 14A-2 also show the values of the predicate FIFO 1312for each cycle, with the left-most bit being the input or “first” bit.As explained above, execution of a coalesced nested loop begins with aNLCINIT instruction, which is unitless. Further, in cycle 0, a TICKinstruction is initially executed; however, it should be appreciatedthat this tick may be omitted by altering subsequent GETP instructionlogic (e.g., to change the offset into the predicate FIFO 1312 by −1).Only one TICK instruction has occurred before the execution of the GETPinstruction in cycle 1, which obtains the predicate for theinitialization of the accumulator (the MVK (move constant) instructionin cycle 2), and thus the offset into the predicate FIFO 1312 for theGETP instruction is zero. The GETP instruction in cycle 1 obtains thefirst bit of the predicate FIFO 1312 for the outer loop. In some cases,the predicate FIFO 1312 is initialized to have an outer loop value(e.g., a 1) in its first input bit. In this case, because the loop hasjust begun and a TICK instruction was executed in the previous cycle,the first bit in the predicate FIFO 1312 is true (1), which is stored inregister A5 and thus the MVK instruction will execute on this first timethrough the inner loop. In FIGS. 14A-1 and 14A-2, bolded font indicateswhen the obtained predicate is true and thus the outer loop instructionexecutes.

In cycle 2, since A5 contains a predicate value of true (1), the MVK(move constant) instruction is executed to load register B0 with a valueof 0. However, in the second iteration starting on cycle 8, the MVKinstruction does not execute because the TICK instruction in cycle 8pushes a 0 into the predicate FIFO 1312, causing the GETP instruction incycle 9 to return a false (0).

On the third iteration beginning in cycle 16, three inner loopiterations have executed and thus the outer loop code after the innerloop code (e.g., the store of the accumulation result) should execute.For this reason, the GETP instruction in cycle 22, which returns thepredicate for the SDD (store double word) instruction that stores theaccumulation result, has an offset of 2 so that the GETP instructionobtains the predicate from two iterations prior, which is when the outerloop predicate was true (1). In this example, the loop level parameterexplained above is omitted for clarity since there is only one level ofloop nesting in this example.

The example of FIGS. 14A-1 and 14A-2 continues with the second iterationof the outer loop, where the initialization of the accumulator (e.g.,the MVK instruction) is executed since the TICK instruction in cycle 24pushes a true (1) into the predicate FIFO 1312, causing the GETP incycle 25 to return that value. The loop iterations continue in a similarfashion through cycles 26-55 as shown in the remainder of FIGS. 14A-1and 14A-2.

FIG. 14B shows a coalesced nested loop that is software pipelined anduses the nested loop controller 1300, 1350 described above. In thisexample, as above, the inner loop count is 3 and the outer loop count is5, resulting in a total of 15 original inner loop iterations. In thisexample, a new iteration of the coalesced loop begins every cycle. Incycle 0, the TICK instruction pushes a true (1) to the predicate FIFO1312, while in cycle 1 the GETP instruction having an offset of 0obtains the 1 off of the front of the predicate FIFO 1312 (e.g., duringa first part of the cycle). The TICK instruction in cycle 1 causes thecomparator 1310 of the nested loop controller 1300 to push a 0 to thepredicate FIFO 1312 (e.g., during a second part of the cycle). In thisexample, the GETP instruction reads the predicate FIFO 1312 during afirst part of the cycle, such that the 1 from the previous cycle isstill at the front of the predicate FIFO 1312, and thus an offset of 0is used for the GETP instruction.

In FIG. 14B, the instructions pipe-up as each successive iteration isstarted in the prolog of the software pipelined loop. As in FIGS. 14A-1and 14A-2, bolded font indicates when an obtained predicate is true andthe predicated, outer loop instruction executes. Once an execute packetcontains all possible instructions for the coalesced nested loop, asbegins in cycle 7, the loop is said to be in the kernel. The prologrefers to the cycles that precede and build to the kernel (e.g., cycles0-6), while the epilog refers to the cycles that follow the kernel andwind down the loop (e.g., cycles 15-21). In cycle 7, the softwarepipelined coalesced loop enters the kernel stage, where the loop repeatsthe same sequence of instructions (in this example, only one cycle ofinstructions as the initiation interval is 1 cycle). In cycle 8, thethird GETP instruction is executed. This GETP instruction obtains thepredicate for the store of the accumulated value in register B0.

Thus, the obtained predicate should be true. As can be seen, an offsetof 7 for the GETP instruction obtains the outer loop predicate from thefirst iteration, when the outer loop predicate was true. The inner loopcounter 1308 (ILC) is decremented on each cycle and reset to 2 when 3iterations are completed. At the end of each 3 iterations, the outerloop counter 1302 (OLC) is decremented. In this case, when the OLC andILC reach zero, the branch in the kernel is not taken, so control fallsinto the epilog. The epilog code then pipes-down the loop, ending with aGETP instruction and store of the final accumulated value.

FIG. 14C shows a coalesced nested loop that uses the nested loopcontroller 1300, 1350 described above, and that has been softwarepipelined, with full epilog collapsing performed. FIG. 14C is similar toFIG. 14B, except that the kernel is executed extra times to account forthe fact that the epilog has been removed by stage collapsing. In thisexample, the compiler uses an NLCINIT episkew value of 7 to indicate tothe nested loop controller 1300, 1350 to execute the kernel (e.g.,through the use of additional BNL instructions, which are explainedfurther below) an additional 7 times. In some examples, the compilerdetermines that the over-execution of instructions (indicated by adashed box 1402) is safe and does not affect the outcome of the programor otherwise set up predicates to conditionally execute theseinstructions. For simplicity, in this example predicates tocontrol/prevent over-execution of kernel code are not shown.

The BNL instructions are branch instructions that signify a branch backto the kernel (i.e., the execute packet shown in cycle 9). Executing aBNL instruction causes a branch (e.g., to the kernel) to be taken untila number of iterations specified by the episkew parameter are completeafter the inner and outer loop counters 1308, 1302 have reached zero, inthe example where such counters are decremented when advanced. Asexplained above, every TICK instruction reduces the loop count value bydecrementing the inner and outer loop counters 1308, 1302. In oneexample, the total number of ticks is calculated as: OLCNT value*ILCNTvalue+EPISKEW. Whether a branch is taken is determined based on whetherthe ticks counted are less than the total number of ticks calculated, inwhich case the branch is taken. If the ticks counted are greater than orequal to the total number of ticks calculated, the branch is not taken.

FIGS. 14B and 14C thus represent longhand versions of what would bereduced in size in an instruction store (e.g., instruction cache 121).For example, the instruction store contains the prolog instructions, oneinstance of the kernel that is repeatedly branched back to until thenested loop controller 1300 inner loop counter 1308 reaches thethreshold (e.g., 0) for the final time (e.g., once the outer loopcounter 1302 has also reached the threshold, or 0), which occurs incycle 14 as shown, and the epilog instructions. In the example of FIG.14C, the epilog instructions are not included as the epilog has beencollapsed as explained above.

As explained, in the example of FIG. 14C the epilog is furthercollapsed. The epilog is functionally equivalent to the kernel, with theonly difference being that in each execution of the kernel in place of acollapsed epilog cycle, certain of the instructions do not matter,namely those shown as the dashed box 1402. The episkew parameter andregister discussed above take epilog collapsing into account whendetermining how many BNL instructions to take. The NLCINIT instructionspecifies an episkew value, which can be calculated by a compiler(discussed in further detail below) as, for example, a number of TICKinstructions before the first BNL instruction minus a number ofuncollapsed epilog stages. In the current examples, epilog stages areall a single cycle; however, in other examples, an epilog stage mightinclude multiple cycles. Thus, in FIG. 14B, the number of TICKinstructions before the first BNL instruction is 7, while the number ofuncollapsed epilog stages is also 7, which results in an episkewparameter of 0. However, in FIG. 14C, the number of TICK instructionsbefore the first BNL instruction is 7, while the number of uncollapsedepilog stages is 0, which results in an episkew parameter of 7.

The nested loop controller 1300 thus permits a simplified approach togenerating, storing, and accessing predicate values for controllingexecution of instructions in a coalesced nested loop. For example,rather than storing predicate values to registers and loading predicatevalues from registers, both of which require functional unit overhead,not to mention the complexities of keeping track of which predicatevalue is located in which register, the TICK instruction is unitless andthus does not monopolize a functional unit. Further, the GETPinstruction permits simple indexed access into the predicate FIFO 1312.Still further, the NLCINIT instruction allows loop counts to be simplyset, and an episkew counter to be utilized to facilitate collapsing theepilog, further reducing instruction store requirements for a coalescednested loop.

Referring back to FIGS. 13A and 13B, in some examples an interrupt orexception event may occur during the handling of a nested loop. Inresponse to such an event, the DSP 100 operates to save the nested loopcontroller 1300, 1350 registers (e.g., the inner loop counter 1308, theouter loop counter 1302, the predicate FIFOs 1312, 1353, the episkewcounter 1316, and the inner loop reload register 1304). Once theinterrupt or exception event has been handled, the DSP 100 recovers byreloading the registers of the nested loop controller 1300, 1350 from alocation in memory pointed to by an event handling pointer, for example.

FIG. 15 shows an exemplary system 1500 for compiling a nested loop inaccordance with examples of this disclosure. The system 1500 includes acompiler 1502 that is coupled to a DSP 1504, which may be functionallyequivalent to the DSP 100 described above. The DSP 1504 includes aninstruction store 1506 that stores assembly- or object-levelinstructions to be executed by the DSP 1504. The instruction store 1506may be equivalent or similar to the instruction cache 121 describedabove.

The compiler 1502 is configured to receive higher-level software codethat includes a nested loop, in order to compile the nested loop intoassembly- or object-level instructions to be stored in the instructionstore 1506 and subsequently executed by the DSP 1504. The compiler 1502is configured to generate an initialization instruction (e.g., NLCINIT,described above) that is executed prior to the instructions of thenested loop. The initialization instruction initializes a nested loopcontroller, such as the nested loop controllers 1300, 1350 of FIGS. 13Aand 13B, above. In particular, the initialization instructioninitializes an outer loop count value (e.g., outer loop counter 1302)and an inner loop count value (e.g., inner loop counter 1308 and/orinner loop reload register 1304), as well as a predicate FIFO (e.g.,predicate FIFO 1312, 1353).

The compiler 1502 is also configured to coalesce the nested loop byconditioning or predicating the instructions associated with the outerloop. As a result, at least one predicated instruction in the coalescednested loop corresponds to an instruction in an outer loop of the nestedloop being compiled. The process of coalescing a nested loop isdescribed in further detail above, particularly with respect to FIGS.14a and 14B.

The compiler 1502 is also configured to generate a TICK instruction foreach iteration of the coalesced nested loop, as demonstrated in FIGS.14a and 14B. As explained above, the TICK instruction advances the innerloop count value (as well as the outer loop count value, for examplewhen the inner loop count value reaches a threshold) and generallycontrols the advancement of the nested loop controller registers duringexecuting of the coalesced nested loop. The advancing of inner loopcount value (and outer loop count value) also populates the predicateFIFOs 1312, 1353 as explained above.

Further, for each predicated instruction in the coalesced nested loop(e.g., corresponding to an outer loop instruction), the compiler 1502 isconfigured to generate a get predicate instruction (e.g., GETP,described above) including an offset value, which returns a value fromthe predicate FIFO specified by the offset value. In this way, predicatevalues are generated, stored, and accessed in a simplified manner. Forexample, rather than storing predicate values to registers and loadingpredicate values from registers, both of which require functional unitoverhead, not to mention the complexities of keeping track of whichpredicate value is located in which register, the TICK instruction isunitless and thus does not monopolize a functional unit. Further, theGETP instruction permits simple indexed access into the predicate FIFO1312, 1353.

As explained above, in some examples certain outer loops in a nestedloop may not include any instruction other than the loop controlinstruction(s). The compiler 1502 may be configured to collapse suchouter loops that do not contain instructions. Further, in some cases anepilog of the coalesced nested loop may be collapsed, for example bycontinuing to branch to the kernel of the coalesced nested loop afterthe inner loop counter and outer loop counter have reached theirthreshold values (e.g., 0 in the case of decrementing counter valuesinitialized to inner loop count minus one, and outer loop count minusone, respectively). In this case, the compiler 1502 generates theinitialization instruction (e.g., NLCINIT) to initialize the includingan episkew value (e.g., episkew counter 1316) that specifies a number ofadditional iterations, or branches to the kernel, to take once the innerand outer loop counters have reached a threshold value, which is 0 inthe current example.

In the foregoing discussion and in the claims, the terms “including” and“comprising” are used in an open-ended fashion, and thus should beinterpreted to mean “including, but not limited to . . . .” Also, theterm “couple” or “couples” is intended to mean either an indirect ordirect connection. Thus, if a first device couples to a second device,that connection may be through a direct connection or through anindirect connection via other devices and connections. Similarly, adevice that is coupled between a first component or location and asecond component or location may be through a direct connection orthrough an indirect connection via other devices and connections. Anelement or feature that is “configured to” perform a task or functionmay be configured (e.g., programmed or structurally designed) at a timeof manufacturing by a manufacturer to perform the function and/or may beconfigurable (or re-configurable) by a user after manufacturing toperform the function and/or other additional or alternative functions.The configuring may be through firmware and/or software programming ofthe device, through a construction and/or layout of hardware componentsand interconnections of the device, or a combination thereof.Additionally, uses of the phrases “ground” or similar in the foregoingdiscussion are intended to include a chassis ground, an Earth ground, afloating ground, a virtual ground, a digital ground, a common ground,and/or any other form of ground connection applicable to, or suitablefor, the teachings of the present disclosure. Unless otherwise stated,“about,” “approximately,” or “substantially” preceding a value means+/−10 percent of the stated value.

The above discussion is meant to be illustrative of the principles andvarious embodiments of the present disclosure. Numerous variations andmodifications will become apparent to those skilled in the art once theabove disclosure is fully appreciated. It is intended that the followingclaims be interpreted to embrace all such variations and modifications.

What is claimed is:
 1. A nested loop controller, comprising: a firstregister configured to store an outer loop value; a second registerhaving configured to store an inner loop value; a third registerconfigured as a predicate first-in, first-out buffer (FIFO); and acomparator coupled to the second register and to the third register,wherein the nested loop controller is configured to: initialize theouter loop value of the first register to an initial first value;initialize the inner loop value of the second register to an initialsecond value; perform one of an increment or a decrement of the innerloop value of the second register in response to a tick instructionduring execution of a loop; and in response to the inner loop valuereaching a second threshold, reset the inner loop value of the secondregister to the initial second value; and wherein the comparator isconfigured to: shift a first value into the third register when theinner loop value is equal to the second threshold; and shift a secondvalue into the third register when the inner loop value is not equal tothe second threshold.
 2. The nested loop controller of claim 1, wherein:the initial second value is equal to zero; the nested loop controller isconfigured to increment the inner loop value in response to the tickinstruction; and the second threshold is equal to an inner loop countvalue minus one.
 3. The nested loop controller of claim 1, wherein: theinitial second value is equal to an inner loop count value minus one;the nested loop controller is configured to decrement the inner loopvalue in response to the tick instruction; and the second threshold isequal to zero.
 4. The nested loop controller of claim 1, wherein thenested loop controller is configured to perform one of an increment or adecrement of the outer loop value in response to the inner loop valuereaching the second threshold.
 5. The nested loop controller of claim 4,wherein the nested loop controller is configured to, in response to thefirst value reaching a first threshold, cease to reset the inner loopvalue .
 6. The nested loop controller of claim 4, further comprising afourth register configured to store a fourth value, wherein the nestedloop controller is configured to perform one of an increment or adecrement of the fourth value in response to a tick instruction based onthe outer loop value being equal to a first threshold.
 7. The nestedloop controller of claim 1, wherein the first, second, and/or thirdregisters comprise control registers of a digital signal processor.
 8. Amethod for nested loop control, comprising: initializing an outer loopvalue of a first register to an initial first value; initializing aninner loop value of a second register to an initial second value;initializing a third register, having an associated third value, to aninitial third value, wherein the third register is configured as apredicate first-in, first-out buffer (FIFO); performing one ofincrementing or decrementing of the inner loop value in response to atick instruction during executing of a loop; resetting the inner loopvalue to the initial second value in response to the inner loop valuereaching a second threshold; shifting a first value into the predicateFIFO when the inner loop value is equal to the second threshold; andshifting a second value into the predicate FIFO when the inner loopvalue is not equal to the second threshold.
 9. The method of claim 8,wherein the initial second value is equal to zero and the secondthreshold is equal to an inner loop count value minus one, the methodcomprising incrementing the inner loop value in response to the tickinstruction.
 10. The method of claim 8, wherein the initial second valueis equal to an inner loop count value minus one and the second thresholdis equal to zero, the method comprising decrementing the inner loopvalue in response to the tick instruction.
 11. The method of claim 8,further comprising performing one of incrementing or decrementing of theouter loop value in response to the inner loop value reaching the secondthreshold.
 12. The method of claim 11, further comprising ceasing toreset the inner loop value in response to the outer loop value reachinga first threshold.
 13. The method of claim 11, further comprising:initializing a fourth value of a fourth register to an initial fourthvalue; and performing one of incrementing or decrementing of the fourthvalue in response to a tick instruction once the outer loop valuereaches a first threshold.
 14. The method of claim 8, wherein the first,second, and/or third registers comprise control registers of a digitalsignal processor.
 15. An integrated circuit comprising: an inner loopcounter configured to: store an inner loop value; receive a tickinstruction; and perform one of incrementing or decrementing of theinner loop value based on the tick instruction; an outer loop countercoupled to the inner loop counter and configured to: store an outer loopvalue; and perform one of incrementing or decrementing of the outer loopvalue based on the tick instruction and the inner loop value; apredicate shift register configured to store a set of predicate values;and a comparator coupled between the inner loop counter and thepredicate shift register and configured to select between shifting afirst value into the predicate shift register and shifting a secondvalue into the predicate shift register based on the inner loop value.16. The integrated circuit of claim 15, wherein the comparator isconfigured to: shift the first value into the predicate shift registerbased on the inner loop value being equal to an inner loop reset value;and shift the second value into the predicate shift register based onthe inner loop value being not being equal to the inner loop resetvalue.
 17. The integrated circuit of claim 15, wherein the comparator isconfigured to: shift the first value into the predicate shift registerbased on the inner loop value being equal to an inner loop thresholdvalue; and shift the second value into the predicate shift registerbased on the inner loop value being not being equal to the inner loopthreshold value.
 18. The integrated circuit of claim 15 furthercomprising a skew counter configured to: store a skew value; and performone of incrementing or decrementing of the skew value based on the tickinstruction and the outer loop value.
 19. The integrated circuit ofclaim 18, wherein: the outer loop counter is configured to perform oneof incrementing or decrementing of the outer loop value from an outerloop reset value to an outer loop threshold value; and the skew counteris configured to perform the one of incrementing or decrementing of theskew value based on the outer loop value being equal to the outer loopthreshold value.
 20. The integrated circuit of claim 15, wherein thepredicate shift register is configured to provide a subset of the set ofpredicate values based on a get predicate instruction.